package com.shnu.work.service.impl;

import com.shnu.work.entity.UserInformationEntity;
import com.shnu.work.repository.UserInformationRepository;
import com.shnu.work.service.IUserInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * @author Shinomiya Kaguya
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class UserInformationServiceImpl implements IUserInformationService {
    @Autowired
    private UserInformationRepository userInformationRepository;

    @Override
    public UserInformationEntity saveUser(UserInformationEntity user) {
        return userInformationRepository.save(user);
    }

    @Override
    @Cacheable(value = "user")
    public UserInformationEntity getUserInformationEntityByUserAccount(String userAccount) {
        return userInformationRepository.getUserInformationEntityByUserAccount(userAccount);
    }

    @Override
    public List<UserInformationEntity> listAllUndeletedUsers() {
        return userInformationRepository.listAllUndeletedUsers();
    }

    @Override
    public Integer removeUserById(Long id) {
        return userInformationRepository.removeUserById(id);
    }

    @Override
    public Optional<UserInformationEntity> findUserById(Long id) {
        return userInformationRepository.findById(id);
    }
}
